package com.yuyou.fn.service.impl;


import java.util.List;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import cn.emay.sdk.client.api.Client;

import com.yuyou.fn.service.ISmsService;
import com.yuyou.fn.util.Util;

/**
 * Sms 表数据服务层接口实现类
 */
@Service
public class smsServiceImpl implements ISmsService {

    @Value("${dev.env}")
    private boolean dev;

    @Value("${sms.spiNo}")
    private String smsSpiNo;



    @Value("${sms.spiPassword}")
    private String smsSpiPassword;

    @Value("${check.token}")
    private String checkToken;


    @Override
    public int sendSMS(List<String> phoneNos,String token, String content)  throws Exception{

        String s = DigestUtils.md5Hex(Util.join(phoneNos, ",") + checkToken);
        System.out.println(token);
        System.out.println(s);
        System.out.println(Util.join(phoneNos, ","));
        System.out.println(checkToken);
        if (s.equals(token)) {
            try {

                String[] phoneNoArray = phoneNos.stream().toArray(String[]::new);
                Client client = new Client(smsSpiNo, smsSpiPassword);
                int sendResult = client.sendSMS(phoneNoArray, content, 3);
                return sendResult;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                throw e;
            }
        } else {
            return 3;
        }

    }

}